# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=servant
pkgname=haskell-servant
pkgver=0.19.1
pkgrel=65
pkgdesc="A family of combinators for defining webservices APIs"
url="http://haskell-servant.readthedocs.org/"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-base-compat' 'haskell-aeson' 'haskell-attoparsec'
         'haskell-bifunctors' 'haskell-case-insensitive' 'haskell-constraints'
         'haskell-http-api-data' 'haskell-http-media' 'haskell-http-types' 'haskell-mmorph'
         'haskell-network-uri' 'haskell-quickcheck' 'haskell-tagged' 'haskell-sop-core'
         'haskell-singleton-bool' 'haskell-string-conversions' 'haskell-vault')
makedepends=('ghc' 'uusi' 'haskell-hspec' 'haskell-quickcheck-instances')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('f99ed533f6b0ef819880622509cb452ef53e45a950b0712e56393721e61784b98040336fbed01a097a1da08dbfaa4afc8a515b46dea85218a0ae3b4bf9101124')

prepare() {
    cd $_hkgname-$pkgver
    uusi -u bifunctors -u hspec -u hspec-discover -u http-api-data -u singleton-bool $_hkgname.cabal
}

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
